/*
 * Website of log4cpp is: http://log4cpp.sourceforge.net/
 */
#include <fstream>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/PatternLayout.hh"
#include "log4cpp/Priority.hh"
#define LOG_FILE "../log.txt"
using namespace std;

// if you want to use it with no .property file
int test_main(int argc, char** argv) {
    ofstream file_stream(LOG_FILE, ios_base::out);
	log4cpp::Appender *appender1 = new log4cpp::OstreamAppender("console", &file_stream);
	auto pLayout = new log4cpp::PatternLayout();
	pLayout->setConversionPattern("%d: %p %c %x: %m%n");

	appender1->setLayout(pLayout);

	log4cpp::Category& root = log4cpp::Category::getRoot();
	root.setPriority(log4cpp::Priority::WARN);

	root.addAppender(appender1);

	root.info("This is a info");
	root.alert("This is an alert");
	root.warn("This is warn");
	root.debug("this is debug");
	root.error("This is an error");
	root.crit("This is critical");
    root.emerg("This is an emergency");
    root.fatal("This is a fatal");
}

// Otherwise you want to use it with .property file
// Examples can be found at http://log4cpp.sourceforge.net/#propfile
#include "log4cpp/PropertyConfigurator.hh"
int main(){
    std::string initFileName = "../log4cpp.properties";
    log4cpp::PropertyConfigurator::configure(initFileName);

    log4cpp::Category& root = log4cpp::Category::getRoot();

    log4cpp::Category& sub1 =
            log4cpp::Category::getInstance(std::string("sub1"));

    log4cpp::Category& sub2 =
            log4cpp::Category::getInstance(std::string("sub1.sub2"));

    root.warn("Storm is coming");

    sub1.debug("Received storm warning");
    sub1.info("Closing all hatches");

    sub2.debug("Hiding solar panels");
    sub2.error("Solar panels are blocked");
    sub2.debug("Applying protective shield");
    sub2.warn("Unfolding protective shield");
    sub2.info("Solar panels are shielded");

    sub1.info("All hatches closed");

    root.info("Ready for storm.");

    log4cpp::Category::shutdown();

    return 0;

}
